#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <pthread.h>
#include <thread>

std::string toHex(pthread_t tid)
{
    char buffer[64];
    snprintf(buffer,sizeof(buffer),"0x%lx",tid);
    return buffer;
}

void* start(void* args)
{
    std::string name = static_cast<const char*>(args);
    sleep(1);
    while(true)
    {
        std::cout << "I am a new thread, name: " << name << ", thread is: " << toHex(pthread_self()) << std::endl;
        sleep(1);
    }
    return nullptr;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid,nullptr,start,(void*)"thread-1");
    std::cout << "I am a new thread, name: main" << ", thread is: " << toHex(pthread_self())
     << ", NEW thread id: " << toHex(tid) << std::endl;
    pthread_join(tid,nullptr);
    return 0;
}